package net.entelijan.cobean.notification;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

import net.entelijan.cobean.combobox.DefaultComboBoxInitializer;
import net.entelijan.cobean.core.ISingleSelectionListCobean;
import net.entelijan.cobean.core.impl.IPropertyChangeListenerAware;
import net.entelijan.testutil.CobeanTestUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ComboBoxNotificationTestFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	private static Log log = LogFactory
			.getLog(ComboBoxNotificationTestFrame.class);

	private JComboBox comboBox = createComboBox("comboBox");

	private JTextField dummyTextField = createTextField("dummyTextField");

	public ComboBoxNotificationTestFrame(String title) {
		super(title);
		CobeanTestUtil.setComponentNamesFromPropertyNames(this);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		final Container cp = getContentPane();
		cp.setLayout(new FlowLayout());
		cp.add(comboBox);
		cp.add(dummyTextField);
		pack();
	}

	private JComboBox createComboBox(String string) {
		JComboBox re = new JComboBox();
		re.setPreferredSize(new Dimension(100, 20));
		return re;
	}

	private JTextField createTextField(String name) {
		final JTextField re = new JTextField();
		re.setColumns(10);
		re.setName(name);
		return re;
	}

	public static void main(String[] args) {
		ComboBoxNotificationTestFrame tf = new ComboBoxNotificationTestFrame(
				"Notification Test");
		tf.setVisible(true);
		final DefaultComboBoxInitializer<String> ini = new DefaultComboBoxInitializer<String>();
		ini.setCoComboBox(tf.getComboBox());
		final ISingleSelectionListCobean<String> cobean = ini.initialize();
		log.debug("Created cobean: " + cobean);
		if (cobean instanceof IPropertyChangeListenerAware) {
			log.debug(cobean + " is IPropertyChangeListenerAware");
			((IPropertyChangeListenerAware) cobean)
					.setPropertyChangeListener(new RecordingPropertyChangeListener("irrelevant"));
		} else {
			throw new IllegalStateException(
					"Make the cobean IPropertyChangeAware");
		}
		cobean.setValue(CobeanTestUtil
				.createStringList("Nicht ausverkauft trotz Hamsterkäufe"));
	}

	public JTextField getDummyTextField() {
		return dummyTextField;
	}

	public void setDummyTextField(JTextField rightTextField) {
		this.dummyTextField = rightTextField;
	}

	public JComboBox getComboBox() {
		return comboBox;
	}

	public void setComboBox(JComboBox comboBox) {
		this.comboBox = comboBox;
	}

}
